package online.cmagic.structureType.flyweight;

import java.util.Hashtable;

/**
 * @author wsc
 * @date: 2020年04月15日 15:13
 * @since JDK 1.8
 */
public abstract class FlyWeight {
    public abstract void operation(int n);
}

class ConcreteFlyWeight extends FlyWeight{

    @Override
    public void operation(int n) {
        System.out.println("具体的flyWeight:"+n);
    }

}
class UnsharedConcreteFlyWeight extends FlyWeight{

    @Override
    public void operation(int n) {
        System.out.println("不共享的具体FlyWeight:"+n);
    }
}

class FlyWeightFactory {

    private Hashtable<String, FlyWeight> factory = new Hashtable<String, FlyWeight>();

    public FlyWeightFactory(){
        factory.put("X", new ConcreteFlyWeight());
        factory.put("Y", new ConcreteFlyWeight());
        factory.put("Z", new ConcreteFlyWeight());
    }

    public Hashtable<String, FlyWeight> getFactory() {
        return factory;
    }

    public void setFactory(Hashtable<String, FlyWeight> factory) {
        this.factory = factory;
    }

}